//mongodb 操作
var {
	merchants
} = require('../../tools/database/index.js')
//解析用户信息
var userinfo = require('../../tools/NameList/index.js')
//存储照片
var saveImg = require('../../tools/saveImg/index.js')
//解析post 数据
var PostData = require('../../tools/PostData/index.js')
module.exports = async (req, res) => {
	var info = userinfo(req)
	console.log('数据接受中....', info)
	//商品
	var commodity = await PostData(req)
	var img = JSON.parse(commodity.images);
	var images = await saveImg(req, img, commodity.title, commodity.genre)
	var data = {
		images,
		title: commodity.title, //产品名
		genre: commodity.genre, //类别
		price: commodity.price, //价格
		sum: commodity.sum, //库存
		sales_volume: 0, //销量
		evaluates: [], //评价
	}
	//存储图片
	var result = await merchants.warehouse.upDate({
		_id: info._id
	}, {
		$inc: {
			wallet: 1
		},
		$push: {
			commodity: data
		}
	})
	console.log('接受完璧')
	res.send({
		state: 200
	})
}
